import { createRouter, createWebHistory, RouteRecordRaw } from "vue-router";
import HomeView from "../views/HomeView.vue";
import { beforeEach, afterEach } from "./routerValid";
import { gmRouters } from './GM';

const routes: Array<RouteRecordRaw> = [
  {
    path: "/",
    name: "home",
    component: HomeView,
  },
  {
    path: "/about",
    name: "about",
    component: () =>
      import(/* webpackChunkName: "about" */ "../views/AboutView.vue"),
  },
  {
    path: "/modifyPassword",
    name: "modifyPassword",
    component: () =>
      import(/* webpackChunkName: "base" */ "../views/base/ModifyPassword.vue"),
  },
  {
    path: "/noPermission",
    name: "noPermission",
    component: () =>
      import(/* webpackChunkName: "base" */ "@/views/base/NoPermission.vue"),
  },
  {
    path: "/noRoute",
    name: "noRoute",
    component: () =>
      import(/* webpackChunkName: "base" */ "@/views/base/NoRoute.vue"),
  },
  ...gmRouters,
  // {
  //   path: "/cfg/pageMaint",
  //   name: "pageMaint",
  //   component: () =>
  //     import(/* webpackChunkName: "base" */ "@/views/cfg/pageMaint/index.vue"),
  // },
  // {
  //   path: "/cfg/frontPrjMaint",
  //   name: "frontPrjMaint",
  //   component: () =>
  //     import(/* webpackChunkName: "base" */ "@/views/cfg/frontPrjMaint/index.vue"),
  // },
  // {
  //   path: "/cfg/buttonMaint",
  //   name: "buttonMaint",
  //   component: () =>
  //     import(/* webpackChunkName: "base" */ "@/views/cfg/buttonMaint/index.vue"),
  // },
];
declare module 'vue-router' {  
  interface RouterOptions {  
    base?: string  
  }  
}
// 1.返回一个 router 实列，为函数，里面有配置项（对象） history
// const router = createRouter({
//   history: createWebHistory("/gm-web"),
//   routes,
// });
// router.beforeEach(beforeEach)
// router.afterEach(afterEach)
routes.forEach(item => {
  if (!item.path.startsWith('/gm-web') && (window as any).__POWERED_BY_QIANKUN__ ) {
    item.path = '/gm-web' + item.path
  }
 
})
export default routes;
